-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scissors - Araceli #63
base: master
Are you sure you want to change the base?
Conversation
// } | ||
// }, [result]); | ||
|
||
const changePlayers = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great helper function!
changePlayers(); | ||
checkForWinner(); | ||
|
||
}; | ||
|
||
|
||
const checkForWinner = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the logic in here works! With some minor changes it can be updated to update the UI (and pass the tests):
- set a variable (ex: let winner = null) at the top of the function.
- If a winner is ever found, set winner equal to the player that has won (ex, on line 78 winner = squares[0][index].value).
- At the end of the function save the winner in state.
- Create a function that checks the winner state variable and returns a string that contains either "Winner is [winner]" or "The winner is..." and call the function on line 123 inside the tags.
The last piece is to add a check at the top of markSquares that returns if a winner has been found so that squares can not continue to be marked.
// possibly try to use a counter? | ||
|
||
}; | ||
|
||
|
||
const resetGame = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
if (squares[0][index].value===squares[1][index].value && | ||
squares[1][index].value===squares[2][index].value && | ||
squares[0][index].value!=='') { | ||
alert(`Game Finished! Winning Player: ${player}`); | ||
resetGame(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This chunk of code is repeated for rows and diagonals, the only changes are which points are being checked. I recommend thinking about creating a helper function that does this comparison function to improve readability.
Great work on this project! All of the logic for checking for a win works very well. Nice work with the reset extension! This project is green. |
No description provided.